package com.chenwb.concurrency.test;


class SafeCalc {
	static long value = 0L;

	synchronized void addOne() {
		value += 1;
	}

	synchronized static void addOneStatic() {
		value += 1;
	}


	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(()->{
			SafeCalc safeCalc = new SafeCalc();
			for (int i = 0; i < 1; i++) {
				safeCalc.addOne();
			}
		});
		Thread t2 = new Thread(()->{
			for (int i = 0; i < 10000000; i++) {
				SafeCalc.addOneStatic();
			}
		});
		t2.start();
		t1.start();
		t1.join();
		t2.join();
		System.out.println(value);
	}
}
